from django.db import models

# Create your models here.
# 我们重写用户模型类, 继承自 AbstractUser
from Administrative_office_system.utils.BaseModel import BaseModel
import json


class Department(models.Model):
    name = models.CharField(max_length=255, unique=True, verbose_name='名称')
    parent = models.ForeignKey('self', on_delete=models.PROTECT, db_constraint=False, null=True, blank=True, verbose_name='父部门')
    principal = models.CharField(max_length=50, verbose_name="部门负责人")
    principal_account = models.CharField(default='',max_length=50, verbose_name="部门负责人账号")
    director = models.CharField(default='',max_length=50, verbose_name="主任")
    deputy_director = models.CharField(default='',max_length=50, verbose_name="副主任")
    head_nurse = models.CharField(default='',max_length=50, verbose_name="护士长")
    nurse_account = models.CharField(default='',max_length=50, verbose_name="护士长账号")
    # level = models.CharField(default='',max_length=32, verbose_name="级别")
    # department_code = models.CharField(default='',max_length=50, verbose_name="部门代码")
    # department_attribute = models.CharField(default='',max_length=50, verbose_name="部门属性")
    # incorporation_date = models.CharField(default='',max_length=50, verbose_name="成立日期")
    # cancellation_date = models.CharField(default='',max_length=50, verbose_name="撤销日期")
    # marks = models.CharField(default='',max_length=50, verbose_name="备注")
    # department_english_name = models.CharField(default='',max_length=50, verbose_name="部门英文名称")
    # department_full_name = models.CharField(default='',max_length=255, verbose_name="部门全称")

    def __unicode__(self):
        return self.name

class station_table(models.Model):
    stationName = models.CharField(max_length=255, unique=True, verbose_name='岗位名称')
    stationNum = models.IntegerField(unique=True, verbose_name="岗位编号")
    category = models.CharField(max_length=50, verbose_name="所属类别")
    parent = models.CharField(max_length=50, verbose_name='所属部门')
    position_statement = models.TextField(verbose_name="岗位职责")
    job_description = models.TextField(verbose_name="岗位描述")

class model_name(models.Model):
    name = models.CharField(max_length=255, unique=True, verbose_name='模块名称')

class submodule(models.Model):
    name = models.CharField(max_length=255, unique=True, verbose_name='模块名称')
    parent_module_id = models.CharField(max_length=10, verbose_name='父模块ID')

class role_permission(models.Model):                # 角色对应的权限表
    character = models.CharField(max_length=255, unique=True, verbose_name='角色名称')
    permission = models.TextField(verbose_name="权限字典")
    remark = models.TextField(verbose_name="备注")

class classification_cement(models.Model):          # 公告分类
    name = models.CharField(max_length=255, unique=True, verbose_name='公告名称')
    parent = models.ForeignKey('self', on_delete=models.PROTECT, db_constraint=False, null=True, blank=True, verbose_name='上级分类')
    def __unicode__(self):
        return self.name

class notification(models.Model):               # 通知公告表
    name = models.CharField(max_length=255, verbose_name='公告名称')
    open = models.CharField(max_length=20, verbose_name='是否公开')
    accept_people = models.TextField(verbose_name="接收人员")
    announcement_time = models.CharField(max_length=100, verbose_name='公告时间')
    category = models.CharField(max_length=50, verbose_name="所属类别")
    content = models.TextField(verbose_name="公告内容")
    create_people = models.CharField(max_length=100, verbose_name='创建人')
    adjunct = models.TextField(verbose_name="附件")
    readId = models.TextField(verbose_name="已读人员ID", default="")


class news_management(models.Model):               # 新闻管理表
    name = models.CharField(max_length=255, verbose_name='新闻标题')
    release_time = models.CharField(max_length=100, verbose_name='发布时间')
    cover_picture = models.TextField(verbose_name="封面图片")
    content = models.TextField(verbose_name="新闻内容")
    create_people = models.CharField(max_length=100, verbose_name='创建人')
    adjunct = models.TextField(verbose_name="附件")


class custom_form(models.Model):               # 自定义表单
    name = models.CharField(max_length=255, verbose_name='表单标题')
    form_html = models.TextField(verbose_name="表单前端代码")
    flow = models.TextField(verbose_name="流程图")
    category = models.CharField(max_length=255, verbose_name='流程类别')
    is_del = models.BooleanField(default=False, verbose_name="是否删除")


class application(models.Model):               # 申请信息表
    name = models.CharField(max_length=255, verbose_name='申请人姓名')
    form_name = models.CharField(max_length=255, verbose_name='表单名称')
    department = models.CharField(max_length=255, verbose_name='所属部门')
    apply_time = models.CharField(max_length=50, verbose_name="申请时间")
    apply_detail = models.TextField(verbose_name="申请详情")
    apply_url = models.CharField(max_length=255, verbose_name="表单地址")
    status = models.CharField(max_length=50, verbose_name="流程状态")
    form_id = models.TextField(verbose_name="表单ID")
    present = models.TextField(verbose_name="当前节点")
    flow_status = models.TextField(verbose_name="流程审批状态json")
    flow_str = models.TextField(default='',verbose_name="流程图")
    is_read = models.BooleanField(default=False,verbose_name="流程结束申请人知否已读")


class delegation_table(models.Model):               # 委托流程总表
    form_name = models.CharField(max_length=100, verbose_name='表单名称')
    consignor = models.CharField(max_length=100, verbose_name='委托人')
    mandatary = models.CharField(max_length=100, verbose_name='被委托人')
    create_time = models.CharField(max_length=100, verbose_name='委托时间')
    flowid = models.CharField(max_length=20, verbose_name='申请ID')
    formid = models.CharField(max_length=20, verbose_name='表单ID')
    look_check = models.CharField(max_length=20, verbose_name='是否查看')

class CompletedProcess(BaseModel):               # 申请信息表
    application_id = models.IntegerField(verbose_name='申请信息表ID')
    user_name = models.CharField(max_length=255, verbose_name='处理人账号')
    real_name = models.CharField(max_length=255, verbose_name='处理人真实姓名')
    status = models.CharField(default='',max_length=50, verbose_name='流程状态')


class official_serial_number(models.Model):               # 公文编号表
    transceiver_type = models.CharField(default='',max_length=100, verbose_name='收发类型')
    number_type = models.CharField(default='',max_length=100, verbose_name='编号类型')
    serial_definition = models.CharField(default='',max_length=100, verbose_name='编号定义')


class doc_template(models.Model):               # 公文模版表
    name = models.CharField(max_length=255, verbose_name='模版名称')
    file_header = models.TextField(verbose_name="word文件头")
    file_end = models.TextField(verbose_name="word文件尾")


class post_single(models.Model):               # 发文单
    model_url = models.CharField(default='',max_length=255, verbose_name='模版名称')
    official_type = models.CharField(max_length=50, verbose_name='公文类型')
    number_type = models.CharField(max_length=50, verbose_name='编号类型')
    post_name = models.CharField(max_length=100, verbose_name='发文字号')
    accuracy_class = models.CharField(max_length=50, verbose_name='密级程度')
    urgency_degree = models.CharField(max_length=50, verbose_name='紧急程度')
    title = models.CharField(max_length=255, verbose_name='标题')
    subject_term = models.CharField(max_length=255, verbose_name='主题词')
    lord_send_unit = models.CharField(max_length=255, verbose_name='主送单位')
    cc_unit = models.CharField(max_length=255, verbose_name='抄送单位')
    drafter = models.CharField(max_length=100, verbose_name='拟稿人')
    is_department = models.CharField(max_length=100, verbose_name='拟稿单位')
    is_the_date = models.CharField(max_length=100, verbose_name='拟稿日期')
    make_draft = models.TextField(verbose_name="核稿")
    countersign = models.TextField(verbose_name="会签")
    sign_issue = models.TextField(verbose_name="签发")
    main_body = models.CharField(max_length=500, verbose_name='正文链接')
    accessory = models.CharField(max_length=255, verbose_name='附件链接')
    current_node = models.CharField(max_length=255, verbose_name='当前节点')
    the_next_node = models.CharField(max_length=255, verbose_name='下一节点')
    run_mode = models.CharField(max_length=50, verbose_name='执行方式')
    task_executor = models.TextField(verbose_name="任务执行人")
    process_node = models.TextField(verbose_name="流程节点")
    status = models.CharField(max_length=10, verbose_name='公文状态', default=1)            # 1、审批中，2、驳回，3、通过，4、不通过
    personnel_do = models.TextField(verbose_name="已办人员", default="")
    Dis_personnel = models.TextField(verbose_name="分发接受人员", default="")
    accepted = models.TextField(verbose_name="已接受人员", default="")
    printed_copies = models.CharField(max_length=10, verbose_name='印发份数', default=1)
    be_consist = models.CharField(max_length=225, verbose_name='是由', default="")
    public_opinion = models.CharField(max_length=50, verbose_name='公开意见', default="")
    intranet_public = models.CharField(max_length=15, verbose_name='内部网公开', default="")
    rests = models.CharField(max_length=225, verbose_name='其他', default="")
    doc_file_type = models.CharField(max_length=10, verbose_name='公文发文类型', default=1)
    Pdf_href = models.CharField(max_length=1000, verbose_name='PDF链接', default=1)
    attachment_list = models.TextField(verbose_name='公文附件列表', default=json.dumps([]))
    node_end_time = models.CharField(max_length=50, verbose_name='上一节点结束时间', default="")
    type = models.CharField(max_length=30, default="内部发文")

class attendance(models.Model):               # 考勤表
    username = models.CharField(max_length=255, verbose_name='用户名', default='')
    punch_time = models.CharField(max_length=100, verbose_name='考勤日期')      # 2021-10-16
    sign_time = models.CharField(max_length=100, verbose_name='签到时间')       # 05:00
    work_status = models.CharField(max_length=10, verbose_name='考勤状态')          # 1、正常，2、迟到， 3、早退
    sign_way = models.CharField(max_length=50, verbose_name='签到方式')         # 手机、电脑
    sign_type = models.CharField(max_length=10, verbose_name='签到类型')           # 1、上班、2、下班



class schedule(models.Model):               # 日程表
    username = models.CharField(max_length=255, verbose_name='用户名', default='')
    schedule_name = models.CharField(max_length=255, verbose_name='行程标题', default='')
    schedule_adress = models.CharField(max_length=255, verbose_name='行程地点', default='')
    start_time = models.CharField(max_length=50, verbose_name='行程开始时间', default='')
    end_time = models.CharField(max_length=50, verbose_name='行程结束时间', default='')
    all_day = models.CharField(max_length=50, verbose_name='是否是全天', default='')


class haveOffice(models.Model):               # 已办公文
    username = models.CharField(max_length=255, verbose_name='已办人员用户名', default='')
    real_name = models.CharField(max_length=255, verbose_name='已办人员真实姓名', default='')
    post_name = models.CharField(max_length=100, verbose_name='发文编号', default='')
    document_name = models.CharField(max_length=255, verbose_name='公文标题', default='')
    document_id = models.CharField(max_length=11, verbose_name='公文ID', default='')
    approveTime =  models.CharField(max_length=50, verbose_name='审批时间', default='')
    handle_type = models.CharField(max_length=50, verbose_name='办理类型', default='')
    type = models.CharField(max_length=30, default="内部发文")



class DepartmentDetail(BaseModel):
    # 序号	选择	部门编码	部门名称	负责人	副主任	部门属性	电话	传真	地址	邮政编码	电子邮件	信用额度	信用等级	信用天数	批准文号	批准单位	成立日期	撤销日期	备注	部门英文名称	部门全称
    name = models.CharField(max_length=255, verbose_name='部门名称')
    parent = models.ForeignKey('self', on_delete=models.PROTECT, db_constraint=False, null=True, blank=True, verbose_name='父部门')
    principal = models.CharField(max_length=50, verbose_name="部门负责人")
    deputy_director = models.CharField(max_length=50, verbose_name="副主任")
    department_code = models.CharField(default='',max_length=50, verbose_name="部门代码")
    tel = models.CharField(default='',max_length=50, verbose_name="电话")
    fax = models.CharField(default='',max_length=50, verbose_name="传真")
    address = models.CharField(default='',max_length=50, verbose_name="地址")
    postal_code = models.CharField(default='',max_length=50, verbose_name="邮政编码")
    email = models.CharField(default='',max_length=50, verbose_name="电子邮件")
    credit_limit = models.CharField(default='',max_length=50, verbose_name="信用额度")
    credit_rating = models.CharField(default='',max_length=50, verbose_name="信用等级")
    credit_days = models.CharField(default='',max_length=50, verbose_name="信用天数")
    approval_number = models.CharField(default='',max_length=50, verbose_name="批准文号")
    approval_unit = models.CharField(default='',max_length=50, verbose_name="批准单位")
    department_attribute = models.CharField(default='',max_length=50, verbose_name="部门属性")
    incorporation_date = models.CharField(default='',max_length=50, verbose_name="成立日期")
    cancellation_date = models.CharField(default='',max_length=50, verbose_name="撤销日期")
    marks = models.CharField(default='',max_length=50, verbose_name="备注")
    department_english_name = models.CharField(default='',max_length=50, verbose_name="部门英文名称")
    department_full_name = models.CharField(default='',max_length=255, verbose_name="部门全称")

    def __unicode__(self):
        return self.name

# 会议室审批已办表
class conference_ready(BaseModel):
    meeting_id = models.CharField(max_length=12, verbose_name='会议申请ID', default="")
    name = models.CharField(max_length=255, verbose_name='申请人姓名')
    department = models.CharField(default='', max_length=100, verbose_name="申请部门")
    apply_time = models.CharField(default='', max_length=100, verbose_name="申请时间")
    apply_url = models.CharField(default='', max_length=100, verbose_name="详情链接")
    approver = models.CharField(default='孔智慧', max_length=100, verbose_name="审批人")
    status = models.CharField(max_length=30, verbose_name="流程状态")
    option = models.CharField(max_length=255, verbose_name="审批意见", default="")


class Staffing(BaseModel):
    user = models.ForeignKey(
        'personal_center.User',
        verbose_name="人员",
        blank=False,
        null=False,
        on_delete=models.CASCADE)
    station = models.CharField(default='', max_length=32, verbose_name="岗位")
    post_personnel = models.ManyToManyField('personal_center.User', verbose_name='岗位人员', related_name='Staffing_users', blank=True)
    job_description = models.CharField(default='', max_length=1000, verbose_name="岗位说明", null=True)
